package com.human.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.human.server.entity.Departments;
import com.human.server.model.R;
import com.human.server.model.request.DepartmentsRequest;
import com.human.server.service.impl.DepartmentsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/human/departments")
public class DepartmentsController {


    @Autowired
    private DepartmentsServiceImpl departmentsService;

    @PostMapping("page")
    public R page(@RequestBody DepartmentsRequest request) {

        return R.success(departmentsService.page(request, new LambdaQueryWrapper<>()));
    }

    @PostMapping("add")
    public R add(@RequestBody Departments departments) {
        return R.success(departmentsService.save(departments));
    }

    @PostMapping("update")
    public R update(@RequestBody Departments departments) {
        return R.success(departmentsService.updateById(departments));
    }

    @PostMapping("delete")
    public R delete(@RequestBody Departments departments) {
        return R.success(departmentsService.removeById(departments.getId()));
    }

    @PostMapping("query")
    public R query(@RequestBody Departments departments) {
        return R.success(departmentsService.getById(departments.getId()));
    }

    /**
     * list
     */
    @PostMapping("list")
    public R list() {
        return R.success(departmentsService.list());
    }

    /**
     * kpiIds
     */
    @PostMapping("kpiIds")
    public R kpiIds(@RequestBody Departments departments) {
        return R.success(departmentsService.kpiIds(departments));
    }

}
